package cn.ad.server.common.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

/**
 * 
 * @author wangwei
 *
 */
public class FileUtils {

	public static void main(String[] args) throws Exception {
			read("E:/adservereclipwork/adserver-web/src/main/resources/bes.json","utf-8");
	}
	
	/**
	 * 读取文件内容。
	 * @param file
	 * @param charsetName
	 * @return
	 * @throws Exception
	 */
	public static String read(String file,String charsetName) throws Exception {  
        String s = null;  
        StringBuffer sb = new StringBuffer();  
        File f = new File(file);  
        if (f.exists()) {  
            try {  
                BufferedReader br =  
                    new BufferedReader(new InputStreamReader(new FileInputStream(f),charsetName));  
                while ((s = br.readLine()) != null) {  
                    sb.append(s);  
                }  
                return sb.toString();
            } catch (Exception e) {  
            	throw e;
            }  
        } else { 
        	throw new Exception("specific file no exist:"+file);
        }  
    }  

}
